<template>
  <a-drawer
    title="审查"
    width=450
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="planReviewVisible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-form :form="form">
      <a-row :gutter="48">

        <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="准考证号">
              <a-input  v-decorator="['ksbh', { rules: [{ required: true, message: '请输入准考证号!' }]},{initialValue:postParams.ksbh}]" placeholder="请输入..." />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="考生姓名">
              <a-input v-decorator="['ksxm', {rules: [{ required: true, message: '请输入考生姓名!' }] },{initialValue:postParams.ksxm}]" placeholder="请输入..." />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取导师">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  v-decorator="['lqdsId', { rules: [{ required: true, message: '请选择!' }] }]">
                <a-select-option v-for="i in selectMenu.ds" :key="i.id" :value="i.id">{{ i.xm }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="录取类别">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  @change="lbChange" v-decorator="['lqlbm', {rules: [{ required: true, message: '请选择!' }] }]">
                <a-select-option v-for="i in TYPE0362" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="培养模式">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  @change="yxChange" disabled v-decorator="['pymsm', {rules: [{ required: true, message: '请选择!' }] }]">
                <a-select-option v-for="i in TYPE0347" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="添加定向单位">
              <a-input placeholder="请输入..." :disabled="isDisable"  v-decorator="['dxwpdwmc',{rules:[{required:isWp,message:'请输入定向单位'}]},{initialValue:''}]"  />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="学制">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  v-decorator="['xz', {rules: [{ required: true, message: '请选择!' }] }]">
                <a-select-option v-for="i in TYPE0301" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}"  >
            <a-form-item label="全额资助">
              <a-switch v-model="postParams.qezz" />
            </a-form-item>
          </a-col>
      </a-row>
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button style="margin-right: .8rem" @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
      <a-button @click="reset" :loading="loading">重置</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
}

const selectArr = ['TYPE0347','TYPE0362','TYPE0301']
export default {
  props: {
    planReviewVisible: {
      default: false
    },
    info: {
      default: () => ({})
    }
  },
  components: {
    STable
  },
  data () {
    return {
      formItemLayout,
      loading: false,
      isDisable:true,
      isWp:true,
      postParams: {

      },
      form:this.$form.createForm(this),
      selectMenu: {
        yx: [] // 院系
      }
    }
  },
   beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  watch: {
    info (val) {
      this.form.resetFields();
      console.log(111,val)
      this.postParams={}
      this.postParams = {
        ksbh:val.ksbh,
        ksxm:val.ksxm,
        id:val.id,
        lqdsId:val.lqdsId,
        lqlbm:val.lqlbm,
        pymsm:val.pymsm,
        qezz:val.qezz,
        bkyxsm:val.bkyxsm,
        bkzydm:val.bkzydm,
        bkyjfxm:val.bkyjfxm,
        zsxn:val.zsxn,
        lqdsxm:val.lqdsxm,
        bkdsymId: val.bkdsymId
      }
      if(!this.info.lqdsId){
        this.info.lqdsId = this.info.bkdsymId
      }
       if(this.postParams.bkzydm){
        if(this.postParams.bkzydm.slice(2,3) == '5' || this.postParams.bkzydm.slice(2,3) == '6'){
          this.form.getFieldDecorator('pymsm', {initialValue: '02'})
        }else {
          this.form.getFieldDecorator('pymsm', {initialValue: '01'})
        }
      }

      if(this.postParams.lqlbm == '12'){
          this.isWp = true
          this.isDisable = false
        }else if(this.postParams.lqlbm == '11'){
        this.isWp = false
        this.isDisable = true
        }else {
          this.isWp = false
          this.isDisable = false
        }
      this.form.setFieldsValue({'ksbh' : this.info.ksbh || ''})
      this.form.setFieldsValue({'ksxm' : this.info.ksxm || ''})
      this.form.setFieldsValue({'lqdsId': this.info.lqdsId || ''})
      this.form.setFieldsValue({'lqlbm': this.info.lqlbm || this.info.bklbm || ''})
      this.form.setFieldsValue({'dxwpdwmc': this.info.dxwpdwmc || ''})
      this.form.setFieldsValue({'xz' : this.info.xz || ''})
      if(this.postParams.qezz==0){
        this.postParams.qezz=false
      }else{
        this.postParams.qezz=true
      }
      let params={
        ssyxm:this.postParams.bkyxsm,
        yjfxm:this.postParams.bkyjfxm,
        zym:this.postParams.bkzydm,
        zsxn:this.postParams.zsxn
      }
      this.$api.base.getGuide(params).then(res=>{
        this.$set(this.selectMenu,'ds',res.data)
      })
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0347: state => state.app['TYPE0347'], // 年级
      TYPE0362: state => state.app['TYPE0362'],
      TYPE0301: state => state.app['TYPE0301']
    })
  },

  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    reset () {
      this.data = []
    },
    // 选择院系
    yxChange (code) {
    },
    lbChange(code){
      this.form.setFieldsValue({'dxwpdwmc':''})
      if(code){
        if(code == '12'){
          this.isWp = true
          this.isDisable = false
          this.form.setFieldsValue({'dxwpdwmc': this.info.dxwpdwmc || ''})
        }else if(code == '11'){
          this.isWp = false
          this.isDisable = true
        }else {
          this.isWp = false
          this.isDisable = false
        }
         this.$nextTick(() => {
        this.form.validateFields(['dxwpdwmc'], { force: true });
      });
      }
    },
    // 选择招生年度
    zsndChange () {

    },
    // 关闭
    onClose () {
      // this.form.resetFields();

      this.$emit('close')
    },
    // 保存
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (err) {
           this.$message.error("请选择必填项")
        }else{
           if(this.postParams.qezz==false){
        this.postParams.qezz=0
      }else{
        this.postParams.qezz=1
      }
      let paramms = Object.assign({
          id:this.postParams.id,
         qezz:this.postParams.qezz
        }, this.form.getFieldsValue())
      this.$api.doctorRecruit.enrollUpate(paramms).then(res=>{
        //  this.form.resetFields();
        // this.info={}
        this.$emit('success')
      })
        }
      })
    },
    handleDelete (key) {
      const dataSource = [...this.data]
      this.data = dataSource.filter(item => item.key !== key)
    },
    // 重置
    reset(){
      let paramms = {
        id: this.info.id
      }
      this.$api.doctorRecruit.resetLqfs(paramms).then(res=>{
        this.$message.success(res.msg)
        this.$emit('close')

      })
    }
  }
}
</script>
